package com.lenin.omena.client.event;

import java.util.List;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.lenin.omena.shared.AddProduceResult;
import com.lenin.omena.shared.DeleteProduceResult;
import com.lenin.omena.shared.domain.Produce;

public class ProduceListChangeEvent extends GwtEvent<ProduceListChangeEventHandler> {

	public static Type<ProduceListChangeEventHandler> TYPE = new Type<ProduceListChangeEventHandler>();

	public static HandlerRegistration register(final EventBus eventBus,
			final ProduceListChangeEventHandler handler) {

		return eventBus.addHandler(ProduceListChangeEvent.TYPE, handler);

	}

	private List<Produce> produceList;
	
	public ProduceListChangeEvent(DeleteProduceResult result) {
		this.produceList = result.getProduce();
	}
	
	public ProduceListChangeEvent(AddProduceResult result) {
		this.produceList = result.getProduce();
	}
	
	
	public List<Produce> getProduce() {
		return produceList;
	}
	
	@Override
	public Type<ProduceListChangeEventHandler> getAssociatedType() {
		return ProduceListChangeEvent.TYPE;
	}

	@Override
	protected void dispatch(final ProduceListChangeEventHandler handler) {
		handler.onProduceListChange(this);
	}

}